/**
 * @author Jun
 * on Apr 24, 2012, 2012
 */
package com.fastwire.carriere.schedule.runnable;

import com.fastwire.carriere.common.constant.AppConstants;
import com.fastwire.carriere.common.util.CommonLogger;
import com.fastwire.carriere.rad.controller.RadProcessController;
import com.fastwire.carriere.rad.controller.RadProcessControllerImp;

/**
 * @author Jun
 * on May 1, 2012, 2012
 */
public class RadDiscoveryThread implements Runnable {

	/** The type. */
	private final String type;
	private final String radIP;

	/**
	 * Instantiates a new u2k discovery thread.
	 * 
	 * @param type
	 *            the type
	 */
	public RadDiscoveryThread(String type, String ip) {
		super();
		this.type  = type;
		this.radIP = ip;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {

		RadProcessController ctler = new RadProcessControllerImp();
		try {
			if (AppConstants.DISCOVERY_RAD_FULL.equals(type)) {
				CommonLogger.info(this, "start rad full discovery");
				ctler.fullDiscovery();
			}
			else if (AppConstants.DISCOVERY_RAD_ADHOC.equals(type)) {
				CommonLogger.info(this, "start rad adhoc discovery: " + radIP);
				ctler.adhocDiscovery(radIP);
			}
			else   // added by Jun on 20120327 
			{
			    CommonLogger.error(this, "rad discovery type is not correct: " + type);
			}
		} catch (Exception e) {
			e.printStackTrace();
			CommonLogger.error(this, e.getMessage());
		}
	}

}
